//
//  SWNavigationController.m
//  SinaWeibo2
//
//  Created by zhuangqianwei on 16/11/28.
//  Copyright © 2016年 zhuangqianwei. All rights reserved.
//

#import "SWNavigationController.h"
#import "SWBaseViewController.h"
@interface SWNavigationController ()

@end

@implementation SWNavigationController

// 只初始化一次
+ (void)initialize
{
    // 设置项目中item的主题样式
    UIBarButtonItem *item = [UIBarButtonItem appearance];
    
    // Normal
    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
    textAttrs[NSForegroundColorAttributeName] = [UIColor orangeColor];
    textAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:13];
    [item setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
    
    // 不可用状态
    NSMutableDictionary *disableTextAttrs = [NSMutableDictionary dictionary];
    disableTextAttrs[NSForegroundColorAttributeName] = [UIColor lightGrayColor];
    disableTextAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:13];
    [item setTitleTextAttributes:disableTextAttrs forState:UIControlStateDisabled];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationBar.translucent = NO;
}
//重写这个方法能够 拦截所有push进来的控制器
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
    
    if (self.childViewControllers.count > 0) {
        
        viewController.hidesBottomBarWhenPushed = YES;
        if ([viewController isKindOfClass:[SWBaseViewController class]]) {
            SWBaseViewController * vc = (SWBaseViewController *)viewController;
            vc.navigationItem.leftBarButtonItem = [UIBarButtonItem backItemWithimage:[UIImage imageNamed:@"navigationbar_back_withtext"] highImage:[UIImage imageNamed:@"navigationbar_back_withtext_highlighted"] target:self action:@selector(pop) title:@"返回"];
        }else{
            //没有继承根控制器的话 要重新显示导航栏
            self.navigationBar.hidden = NO;
            viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem backItemWithimage:[UIImage imageNamed:@"navigationbar_back_withtext"] highImage:[UIImage imageNamed:@"navigationbar_back_withtext_highlighted"] target:self action:@selector(pop) title:@"返回"];
        }
    }
            //调用父类pushviewController，self.viewControllers数组添加对象viewController
            [super pushViewController:viewController animated:animated];
    
    
    
}
- (void)pop {
    //没有继承根控制器的话 要隐藏导航栏
    self.navigationBar.hidden = YES;
    [self popViewControllerAnimated:YES];
    
}
@end
